<template>
	<view>

		<uv-popup ref="popupPLone" round="8" :safeAreaInsetBottom="false" :closeable="true">
			<view class="payBox">
				<view class="font-36 font-weight">支付金额(元)</view>
				<view class="font-60 font-weight f-t m-t-40">{{shop_earnest_money||0}}元</view>
				<view class="m-b-30 m-t-30" style="width: 100%;height: 2rpx;background-color: #efefef;"></view>
				<button type="primary" @click="submitPlone(order_no)">支付定金</button>
				<view class="flex m-t-30" @click="payShow=!payShow">
					<view class="iconfont icon-weixuanzhong" v-if="!payShow" style="font-size: 40rpx;"></view>
					<view class="iconfont icon-choose f-t" v-else style="font-size: 40rpx;"></view>
					<view class="">我已阅读并同意<text style="color: #385373;" @click.stop="xieYi">《支付协议》</text></view>
				</view>
			</view>
		</uv-popup>

		<uv-popup ref="popupPay" round="8" :safeAreaInsetBottom="false" :closeable="true">
			<scroll-view scroll-y="true" class="payBox">
				<view v-html="pay_agreement">
				</view>
			</scroll-view>
		</uv-popup>

	</view>
</template>

<script>
	export default {
		name: "payModel",
		props: ['order_no','shop_earnest_money'],
		data() {
			return {
				payShow: false,
				pay_agreement: ''
			};
		},
		created() {
			this.getConfig()
		},
		methods: {
			open() {
				this.$refs.popupPLone.open('center');
			},
			getConfig(type) {
				this.$api.sendRequest({
					url: '/api/index/config',
					data: {},
					success: res => {

						this.pay_agreement = res.data.pay_agreement

					}
				})
			},
			submitPlone(order_no) {
				if (!this.payShow) {
					uni.showToast({
						title: '请先勾选协议',
						icon: 'error'
					})
					return
				}
				let data = this.order_no
					uni.requestPayment({
						"provider": "wxpay",
						timeStamp: data.timeStamp, //后端返回的时间戳
						nonceStr: data.nonceStr, //后端返回的随机字符串
						package: data.package, //后端返回的prepay_id
						signType: data.signType, //后端签名算法,根据后端来,后端MD5这里即为MD5
						paySign: data.paySign, //后端返回的签名
						success: res => {
							uni.showModal({
								title: '提示',
								content: '支付成功',
								cancelText: '确定',
								showCancel: false,
								success: resA => {
									this.$refs.popupPLone.close();
								}
							});
						},
						fail(e) {
							uni.showToast({
								title: '取消支付',
								icon: 'error'
							})
						}
					})
			},

			xieYi() {
				this.$refs.popupPay.open('center');
			},
		}
	}
</script>

<style lang="scss">
	.payBox {
		width: 514rpx;
		height: 370rpx;
		border-radius: 16rpx;
		background-color: #fff;
		padding: 30rpx 25rpx;
	}
</style>
